package com.majun.listener;

import com.alibaba.fastjson.JSON;
import com.majun.bean.SysUserDto;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.annotation.SelectorType;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

/**
 * 监听消费某个 topic 下指定 tag 的消息
 * tips: @RocketMQMessageListener 默认 selectorExpression = "*"，表示会
 *       消费指定 topic 下的所有消息，修改属性 selectorExpression = "tagName"
 *       可以让该消息监听器消费某个 topic 下指定 tag 的消息，达到消息过滤的效果。
 *
 * @author zy
 * @date 2020/6/15
 * @since 1.0.0
 */
@Slf4j
@Component
@RocketMQMessageListener(consumerGroup = "tag-consumer", topic = "tag-message",
        selectorExpression = "testTag", selectorType = SelectorType.TAG
)
public class TagMessageListener implements RocketMQListener<SysUserDto> {
    @Override
    public void onMessage(SysUserDto sysUserDto) {
        log.info("消费到了带 tag 的消息: tag = {}, message = {}", "testTag", JSON.toJSONString(sysUserDto));
    }
}
